package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Dto.OrderDTO;
import com.itheima.reggie.common.Result;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 订单
 * @author Yan
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    @PostMapping("/submit")
    public Result<String> submit(@RequestBody Orders orders){

        return orderService.submit(orders);

    }

    @GetMapping("userPage")
    public Result<Page<OrderDTO>> findOrderByPage(Long page, Long pageSize){
        return orderService.findOrderByPage(page,pageSize);

    }

    @GetMapping("/page")
    public Result<Page<Orders>> findByPage(Long page, Long pageSize, Long number, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime,@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime){
        return orderService.findByPage(page,pageSize,number,beginTime,endTime);
    }



}